package com.atguigu.gulimall.gulimallseckkill.Controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.gulimallseckkill.Service.SeckillService;
import com.atguigu.gulimall.gulimallseckkill.to.SeckillSkuRedisTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class SeckillControler {
    @Autowired
    SeckillService seckillService;
    //返回当前时间可以参与的秒杀商品
    @ResponseBody
    @GetMapping("/currentSeckillSkus")
    public R getCurrentSeckillSkus() {
       List<SeckillSkuRedisTo> vos=seckillService.getCurrentSeckillSkus();
        System.out.println(vos);
        return R.ok().setData(vos);
    }
    @ResponseBody
    @GetMapping("/sku/secKill/{skuId}")
    public R skuSeckillInfo(@PathVariable("skuId") Long skuId){
        SeckillSkuRedisTo to= seckillService.getSkuSeckillInfo(skuId);
        return R.ok().setData(to);
    }
    @GetMapping("/kill")
    public String secKill(@RequestParam("killId") String killId, @RequestParam("key") String key, @RequestParam("num")Integer num
    ,Model model){
       String orderSn= seckillService.kill(killId,key, num);
        model.addAttribute("orderSn",orderSn);
        return "success";
    }
}
